#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
	long int i = 0, n, e, f = 1;
	//long f = 1;

	char a, b[2];
	clrscr();
	/******* Start of Input validation ******/
	printf("\n\n\n\n\t\tPress ESC to Quit");

	printf("\n\n\tPlease Enter the Numeric Value.");

	while(1)
	{
		window(43, 7+i, 80, 25);
		a = getche();

		if(a == 27)
		{
			break;
		}

		if(a >= 48 && a <= 57)
		{
			printf("                          ");
			b[i] = a;
			i++;
		}
		else
		{
			printf("   This is Not a Valid No.");
		}

		if(i == 1)
		{
			break;
		}
	}
	n = atol(b);

	printf("\n\n\tYour entered numerice value: %d \n\n\tPress any key to continue...", n);
	getch();
	/******* End of Input validation	 ******/

	/***** Start of Factorial Logic ****/
	for(i = n; i >= 1; i--)
	{
		e = f;
		f = f * i;
		printf("\n\n\t\t%ld * %ld = %ld", i, e, f);
	}

	printf("\n\n\t\tFactorial = %ld", f);
	/***** End of Factorial Logic ****/

	getch();
}